import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class NetWorkDemo extends StatefulWidget {
  const NetWorkDemo({super.key});

  @override
  State<NetWorkDemo> createState() => _NetWorkDemoState();
}

class _NetWorkDemoState extends State<NetWorkDemo> {
  @override
  void initState() {
    // 请求网络数据
    loadData();
    super.initState();
  }

  void loadData() async {
    // 1. 准备请求的地址
    String path = 'https://mock.boxuegu.com/mock/1172/orders';
    // 2. 创建http client
    Dio dio = Dio();
    // 3. 发送请求
    Response res = await dio.get(path);
    if (kDebugMode) {
      print(res.data);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(20),
      child: const Text('测试加载网络数据'),
    );
  }
}
